<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');
class RaovatViewRaovats extends JViewLegacy{
	function display($tpl = null) {
		
		$items = $this->get('Items');
		$pagination = $this->get('Pagination');
		if (count($errors = $this->get('Errors'))){
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
		
		$this->items = $items;
		$this->pagination = $pagination;
		
		$this->state = $this->get('State');
		
		RaovatHelper::addSubmenu('raovats');
		
		$this->addToolBar();
		$this->sidebar = JHtmlSidebar::render();
		parent::display($tpl);
		$this->setDocument();
	}
	
	protected function addToolBar(){
		$canDo = RaovatHelper::getActions();
		JToolBarHelper::title(JText::_('Raovat Manager'), 'Raovat');
		if ($canDo->get('core.create')) 
		{
			JToolBarHelper::addNew('raovat.add', 'JTOOLBAR_NEW');
		}
		if ($canDo->get('core.edit')) 
		{
			JToolBarHelper::editList('raovat.edit', 'JTOOLBAR_EDIT');
		}
		
		
		if ($canDo->get('core.delete')) 
		{
			JToolBarHelper::deleteList('', 'raovats.delete', 'JTOOLBAR_DELETE');
		}
		if ($canDo->get('core.admin')) 
		{
			JToolBarHelper::divider();
			JToolBarHelper::preferences('com_raovat');
		}
		
		JHtmlSidebar::addFilter(
			JText::_('JOPTION_SELECT_PUBLISHED'),
			'filter_published',
			JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)
		);

		JHtmlSidebar::addFilter(
			JText::_('JOPTION_SELECT_CATEGORY'),
			'filter_category_id',
			JHtml::_('select.options', JHtml::_('category.options', 'com_raovat'), 'value', 'text', $this->state->get('filter.category_id'))
		);
	}
	
	protected function setDocument(){
		$document = JFactory::getDocument();
		$document->setTitle(JText::_('Raovat Manager'));
	}
}
